#include"Input.h"

namespace Craft{

	int    InputManger::keys[1024];
	double InputManger::m_lastPosX;
	double InputManger::m_lastPosY;
	bool   InputManger::b_fistMouse = true;
	double InputManger::offsetX = 0;
	double InputManger::offsetY = 0;


	void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
	{
		if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
			glfwSetWindowShouldClose(window, GL_TRUE);

		if (key >= 0 && key < 1024)
		{
			if (action == GLFW_PRESS)
			{
				InputManger::keys[key] = true;
			}
			else if (action == GLFW_RELEASE)
			{
				InputManger::keys[key] = false;
			}
		}
	}


	void mouse_callback(GLFWwindow* window, double xpos, double ypos)
	{
		if (InputManger::b_fistMouse)
		{
			InputManger::m_lastPosX = xpos;
			InputManger::m_lastPosY = ypos;
			InputManger::b_fistMouse = false;
		}

		InputManger::offsetX = xpos - InputManger::m_lastPosX;
		InputManger::offsetY = ypos - InputManger::m_lastPosY;

		InputManger::m_lastPosX = xpos;
		InputManger::m_lastPosY = ypos;

	}


	void mouse_button_callback(GLFWwindow* window, int button, int action, int modes)
	{
		if (button >= 0 && button < 1024)
		{
			if (action == GLFW_PRESS)
			{
				InputManger::keys[button] = true;
			}
			else if (action == GLFW_RELEASE)
			{
				InputManger::keys[button] = false;
			}
		}
	}
}